import sys
import logging
from google.appengine.ext import db

class Customer(db.Model):
    ISPOK = "ISPOK"
    name = db.StringProperty()
    email = db.EmailProperty()
    phone = db.PhoneNumberProperty()  
    address = db.PostalAddressProperty()  
    date = db.DateTimeProperty(auto_now_add=True)
    status = db.StringProperty()
    secret = db.StringProperty()
    isp = db.StringProperty()
    ispid = db.StringProperty()
   
    @staticmethod
    def queryByEmail(email):
        try:
            query = db.Query(Customer)
            query.filter('email =', email)
            item = query.get()
            return item
        except:
            logging.debug(str(sys.exc_info()))
            return None
     
    @staticmethod
    def queryByISPAccount(isp, id):
        try:
            query = db.Query(Customer)
            query.filter('isp =', isp).filter('ispid =',id)
            item = query.get()
            return item
        except:
            logging.debug(str(sys.exc_info()))               
            return None
    
class WishList(db.Model):
    customer = db.ReferenceProperty(Customer)
    name = db.StringProperty()
    url = db.LinkProperty()
    price = db.FloatProperty()
    seq = db.IntegerProperty()   
    
    @staticmethod
    def queryByCustomer(customer):
        try:
            query = db.Query(WishList)
            query.filter('customer =', customer).order('seq')
            items = query.fetch(7)
            return items
        except:
            logging.debug(str(sys.exc_info()))
            return None
